<?php
namespace app\admin\validate;
use think\facade\Db;
use think\Validate;

class Order extends Validate
{

    protected $rule=[
        'id'    =>'require',
        'lists_id'    =>'require',
        'take_name'    =>'require',
        'take_mobile'    =>'require',
        'take_address'    =>'require',
        'pay_code'    =>'require',

    ];
    protected $message = [
        'id.require'    => '关键参数不能为空',

        'lists_id.require'    => '报名id不能为空',
        'take_name.require'    => '收货人姓名不能为空',
        'take_mobile.require'    => '收货人联系方式不能为空',
        'take_address.require'    => '收货人地址不能为空',
        'pay_code.require'    => '支付方式数不能为空',
    ];
    protected $scene = [
        'create' =>['lists_id'],
        'edit' =>['id','take_name','take_mobile','take_address','pay_code'],
    ];

    protected function checkmobile($value,$rule,$data){
        if(!is_numeric($value)){
            return '请输入数字';
        }
        if(strlen($value) != 11){
            return '请输入11位手机号';
        }
        if (!preg_match("/^1[3456789]\d{9}$/", $value)) {
            return '手机号码格式不正确';
        }
        return true;
    }
    protected function checkuniquemobile($value,$rule,$data){
        $one = DB::name('users')->where('mobile','=',$value)->find();
        if($one){
            return '手机号已经存在';
        }
        return true;
    }



}